home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0034_Display PIC Files.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  115 lines

  1. {
  2. Dave Foster
  3.  
  4. > Could anyone please post any routines or help on how
  5. > to read an image into TURBO 6. I can save the image
  6. > in any format, but i need code to be able to display
  7. > it on the screen. Source code would be an advantage!
  8. >
  9. I wrote this Program For a friend to read a image into his Program, and
  10. and I would be happy For any help on how to improve it.
  11. }
  12.  
  13. Program  Read_Image;      { SRC-CODE.PAS   ver 1.00 }
  14. {-----------------------------------------------------------------------------
  15.  Program reads in a binary data File, and displays the image on the screen by
  16.  using "PutPixel" Procedure in the Graph Unit.  The image can be displayed in
  17.  color, or in grey-scale by using the subroutine "Set64Gray" below.
  18.  This is a quick and dirty method to display the image using "PutPixel",
  19.  and I hope someone will be able to show us how to use the "PutImage" to
  20.  display the image quicker.
  21. -----------------------------------------------------------------------------}
  22.  
  23. Uses
  24.   Dos, Crt, Graph;
  25.  
  26. Type
  27.   ByteArray = Array [0..175] of Byte;
  28.  
  29. Var
  30.   Gd, Gm,
  31.   m, n    : Integer;
  32.   buffer  : ByteArray;
  33.   f       : File;
  34.  
  35. {
  36. > Does anyone know how can I get a Graphic mode in VGA in which I
  37. > could use 64 gray level (at least 32)?  Could I keep on using the
  38. > Graphical Procedures in Unit Graph then?
  39.  
  40.  The fragment below will initialize the first 64 VGA color values to
  41.  gray scale.  These colors are valid For any VGA mode (including Text),
  42.  but in most Graphics modes/devices the Borland Graph Unit limits you
  43.  to using only 16 colors.
  44. }
  45.  
  46. Procedure Set64Gray;
  47. { Sets up 64 shades of gray where 0 = black, 63 = full white }
  48. Type
  49.   CRec = Record
  50.     R, G, B: Byte;
  51.   end;
  52. Var
  53.   Regs : Registers;
  54.   I    : Integer;
  55.   G64  : Array [0..63] of CRec;
  56. begin
  57.   { Initialize the block of color values }
  58.   For I := 0 to 63 do
  59.   With G64[I] do
  60.   begin
  61.     R := I;
  62.     G := I;          { Color is gray when RGB values are equal }
  63.     B := I;
  64.   end;
  65.  
  66.   Regs.ax := $1012;      { Dos Function to update block of colors }
  67.   Regs.bx := 0;          { First color to change }
  68.   Regs.cx := 64;         { Number of colors to change }
  69.   Regs.es := seg(G64); { Address of block of color values }
  70.   Regs.dx := ofs(G64);
  71.   intr($10, Regs);
  72. end;
  73.  
  74. begin
  75.   Gd := detect;
  76.   initGraph(Gd, Gm, 'e:\bp\bgi');
  77.  
  78.   { Open the image File which is 250 lines, and 175 pixels per line.
  79.     Each pixel is 1 Byte, and no header data, or Record delimiters.
  80.     File is 43,750 Bytes (250 x 175) in size.  Have look at the input
  81.     File using binary File viewer. }
  82.  
  83.    assign(f, 'DOMINO.DAT');
  84.    reset(f, 175);
  85.  
  86.   { if you enable this, you will be able to see the image in grey-scale,
  87.     but I am not sure if it is quite right.  Currently it seems to display
  88.     only few grey-scale levels instead of the full 64 levels.
  89.  
  90.    }Set64Gray;
  91.  
  92.   { Method used to read the File line at a time, and Write the pixel
  93.     values to the screen. This is bit slow, and it would be lot faster
  94.     by using "PutImage" but I do not know the method For that. }
  95.  
  96.    n := 1;
  97.    While not eof(f) do
  98.    begin
  99.      BlockRead(f, buffer, 1);
  100.      For m := 1 to 175 do
  101.        PutPixel(m, n, buffer[m]);
  102.      n := n + 1;
  103.    end;
  104.  
  105.    close(f);
  106.    readln;
  107.    closeGraph;
  108. end.
  109.  
  110. {
  111. The image File "DOMINO.DAT" used in the Program "SRC-CODE.PAS".
  112. Image File is 250 x 175 pixels (43,750 Bytes).
  113. }
  114.  
  115.